home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWFrming.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  25.3 KB  |  797 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFrming.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWFRMING_H
  13. #include "FWFrming.h"
  14. #endif
  15.  
  16. #ifndef FWPARTNG_H
  17. #include "FWPartng.h"
  18. #endif
  19.  
  20. #ifndef FWPXYFRM_H
  21. #include "FWPxyFrm.h"
  22. #endif
  23.  
  24. #ifndef FWPROXY_H
  25. #include "FWProxy.h"
  26. #endif
  27.  
  28. #ifndef FWUTIL_H
  29. #include "FWUtil.h"
  30. #endif
  31.  
  32. #ifndef FWITERS_H
  33. #include "FWIters.h"
  34. #endif
  35.  
  36. #ifndef FWPRESEN_H
  37. #include "FWPresen.h"
  38. #endif
  39.  
  40. #ifndef FWSELECT_H
  41. #include "FWSelect.h"
  42. #endif
  43.  
  44. #ifndef FWTRACKR_H
  45. #include "FWTrackr.h"
  46. #endif
  47.  
  48. #ifndef FWPRTITE_H
  49. #include "FWPrtIte.h"
  50. #endif
  51.  
  52. #ifndef FWFILEOP_H
  53. #include "FWFileOp.h"
  54. #endif
  55.  
  56. #ifndef FWEMBUTL_H
  57. #include "FWEmbUtl.h"
  58. #endif
  59.  
  60. #ifndef FWPXYITE_H
  61. #include "FWPxyIte.h"
  62. #endif
  63.  
  64. #ifndef FWINSCMD_H
  65. #include "FWInsCmd.h"
  66. #endif
  67.  
  68. // ----- OS Layer -----
  69.  
  70. #ifndef FWODGEOM_H
  71. #include "FWODGeom.h"
  72. #endif
  73.  
  74. #ifndef FWMNUBAR_H
  75. #include "FWMnuBar.h"
  76. #endif
  77.  
  78. #ifndef FWEVENT_H
  79. #include "FWEvent.h"
  80. #endif
  81.  
  82. #ifndef FWCURSOR_H
  83. #include "FWCursor.h"
  84. #endif
  85.  
  86. // ----- OpenDoc Includes -----
  87.  
  88. #ifndef SOM_ODArbitrator_xh
  89. #include <Arbitrat.xh>
  90. #endif
  91.  
  92. #ifndef SOM_Module_OpenDoc_Commands_defined
  93. #include <CmdDefs.xh>
  94. #endif
  95.  
  96. #ifndef SOM_ODDispatcher_xh
  97. #include <Disptch.xh>
  98. #endif
  99.  
  100. #ifndef SOM_ODDraft_xh
  101. #include <Draft.xh>
  102. #endif
  103.  
  104. #ifndef SOM_ODFacet_xh
  105. #include <Facet.xh>
  106. #endif
  107.  
  108. #ifndef SOM_ODInfo_xh
  109. #include <Info.xh>
  110. #endif
  111.  
  112. #ifndef SOM_ODSession_xh
  113. #include <ODSessn.xh>
  114. #endif
  115.  
  116. //========================================================================================
  117. // RunTime Info
  118. //========================================================================================
  119.  
  120. #ifdef FW_BUILD_MAC
  121. #pragma segment fw_embedding
  122. #endif
  123.  
  124. FW_DEFINE_CLASS_M1(FW_CEmbeddingFrame, FW_CFrame)
  125. FW_DEFINE_AUTO(FW_CEmbeddingFrame)
  126.  
  127. //========================================================================================
  128. //    class FW_CEmbeddingFrame
  129. //========================================================================================
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    FW_CEmbeddingFrame::FW_CEmbeddingFrame
  133. //----------------------------------------------------------------------------------------
  134.  
  135. FW_CEmbeddingFrame::FW_CEmbeddingFrame(Environment* ev,
  136.                                         ODFrame* odFrame, 
  137.                                         FW_CPresentation* presentation,
  138.                                         FW_CEmbeddingPart* part,
  139.                                         FW_ResourceId id) :
  140.     FW_CFrame(ev, odFrame, presentation, part, id)
  141. {
  142. }
  143.  
  144. //----------------------------------------------------------------------------------------
  145. //    FW_CEmbeddingFrame::~FW_CEmbeddingFrame
  146. //----------------------------------------------------------------------------------------
  147.  
  148. FW_CEmbeddingFrame::~FW_CEmbeddingFrame()
  149. {
  150. }
  151.  
  152. //----------------------------------------------------------------------------------------
  153. //    FW_CEmbeddingFrame::EmbeddedFrameRequested    
  154. //----------------------------------------------------------------------------------------
  155. // Override should return a proxy and a modified suggestedFrameShape
  156.  
  157. FW_MProxy* FW_CEmbeddingFrame::EmbeddedFrameRequested(Environment *ev,
  158.                                                     FW_MProxy* baseProxy,
  159.                                                     ODFrame* baseFrame,
  160.                                                     ODShape* frameShape,
  161.                                                     ODPart* embeddedPart,
  162.                                                     ODTypeToken viewType,
  163.                                                     ODTypeToken presentation,
  164.                                                     ODID frameGroupID,
  165.                                                     FW_Boolean isOverlaid,
  166.                                                     FW_Boolean isSubFrame)
  167. {
  168. FW_UNUSED(ev);
  169. FW_UNUSED(baseProxy);
  170. FW_UNUSED(baseFrame);
  171. FW_UNUSED(frameShape);
  172. FW_UNUSED(embeddedPart);
  173. FW_UNUSED(viewType);
  174. FW_UNUSED(presentation);
  175. FW_UNUSED(frameGroupID);
  176. FW_UNUSED(isOverlaid);
  177. FW_UNUSED(isSubFrame);
  178.  
  179.     return NULL;
  180. }
  181.  
  182. //----------------------------------------------------------------------------------------
  183. //    FW_CEmbeddingFrame::GetProxy    
  184. //----------------------------------------------------------------------------------------
  185.  
  186. FW_MProxy* FW_CEmbeddingFrame::GetProxy(Environment *ev, ODFrame* embeddedFrame) const
  187. {
  188.     return ((FW_CEmbeddingPart*)GetPart(ev))->GetProxy(ev, embeddedFrame);
  189. }
  190.  
  191. //----------------------------------------------------------------------------------------
  192. //    FW_CEmbeddingFrame::PrivCreateEmbeddedFrame
  193. //----------------------------------------------------------------------------------------
  194.  
  195. FW_DECLARE_THROW_POINT (FW_CEmbeddingFrame_PrivCreateEmbeddedFrame);
  196.  
  197. ODFrame* FW_CEmbeddingFrame::PrivCreateEmbeddedFrame(Environment* ev,
  198.                                                         ODType frameType,
  199.                                                         ODPart *embeddedODPart,
  200.                                                         ODShape* frameShape,    
  201.                                                         ODCanvas* biasCanvas,    // can be null
  202.                                                         ODTypeToken viewType,
  203.                                                         ODTypeToken presentationType,
  204.                                                         FW_Boolean isOverlaid,
  205.                                                         FW_Boolean subFrame)
  206. {
  207.     FW_ASSERT(embeddedODPart);
  208.     
  209.     if (presentationType == 0)
  210.         presentationType = GetPart(ev)->GetSession(ev)->Tokenize(ev, kODPresDefault);
  211.         
  212.     // ----- Normalize the frameShape -----
  213.     FW_CRect box;
  214.     frameShape->GetBoundingBox(ev, (ODRect*)&box);
  215.     if (box.TopLeft() != FW_kZeroPoint)
  216.     {
  217.         FW_CAcquiredODTransform temp = ::FW_NewODTransform(ev, -box.TopLeft());
  218.         frameShape->Transform(ev, temp);
  219.     }
  220.     
  221.     // ----- create the new frame
  222.     ODFrame* embeddedODFrame = GetPart(ev)->GetDraft(ev)->CreateFrame(ev, 
  223.                                                                     frameType,
  224.                                                                     GetODFrame(ev), 
  225.                                                                     frameShape, 
  226.                                                                     biasCanvas,
  227.                                                                     embeddedODPart, 
  228.                                                                     viewType, 
  229.                                                                     presentationType, 
  230.                                                                     subFrame, 
  231.                                                                     isOverlaid);
  232.                                                             
  233.     // Testing: can the caller deal with this method failing?
  234.     FW_CHECK_THROW_POINT (FW_CEmbeddingFrame_PrivCreateEmbeddedFrame);
  235.     
  236.     return embeddedODFrame;
  237. }
  238.  
  239. //----------------------------------------------------------------------------------------
  240. //    FW_CEmbeddingFrame::GetPart
  241. //----------------------------------------------------------------------------------------
  242.  
  243. FW_CEmbeddingPart* FW_CEmbeddingFrame::GetPart(Environment *ev) const
  244. {
  245.     return (FW_CEmbeddingPart*)FW_CFrame::GetPart(ev);
  246. }
  247.  
  248. //----------------------------------------------------------------------------------------
  249. //    FW_CEmbeddingFrame::FrameAdded
  250. //----------------------------------------------------------------------------------------
  251.  
  252. void FW_CEmbeddingFrame::FrameAdded(Environment* ev, ODFrame* odFrame, FW_Boolean fromStorage)
  253. {
  254.     // ----- Call inherited -----
  255.     FW_CFrame::FrameAdded(ev, odFrame, fromStorage);
  256.  
  257.     if (fromStorage)
  258.     {
  259.         // ----- For now, load all the embedded frames -----
  260.         FW_CFrameProxyFrameIterator ite(ev, this);
  261.         for (FW_CProxyFrame* proxyFrame = ite.First(ev); ite.IsNotComplete(ev); proxyFrame = ite.Next(ev))
  262.         {
  263.             proxyFrame->GetFrame(ev);
  264.         }
  265.     }
  266.     else
  267.     {
  268.         // Set the containing frame of any orphan embedded frames
  269.         FW_CPartProxyFrameIterator ite(GetPart(ev));
  270.         for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
  271.         {
  272.             if (proxyFrame->IsOrphan(ev))
  273.                 proxyFrame->SetContainingFrame(ev, this);
  274.         }
  275.     }
  276. }
  277.  
  278. //----------------------------------------------------------------------------------------
  279. //    FW_CEmbeddingFrame::PrivAttachSourceFrame
  280. //----------------------------------------------------------------------------------------
  281. //    FW_CEmbeddingFrame::AttachSourceFrame should not be called if sourceFrame == NULL
  282.  
  283. void FW_CEmbeddingFrame::PrivAttachSourceFrame(Environment* ev, FW_CFrame* sourceFrame)
  284. {
  285.     // Call inherited first to set the fSourceFrame field
  286.     FW_CFrame::PrivAttachSourceFrame(ev, sourceFrame);
  287.     
  288.     FW_ASSERT(sourceFrame != NULL);
  289.  
  290.     // ----- If I am an embedding frame, sourceFrame must be too
  291.     FW_CEmbeddingFrame* embeddingSourceFrame = FW_DYNAMIC_CAST(FW_CEmbeddingFrame, sourceFrame);
  292.     FW_ASSERT(embeddingSourceFrame);
  293.  
  294.     // ----- Duplicate all the embedded frames of sourceFrame -----
  295.     // ----- PrivCreateEmbeddedFrame doesn't create facets, wait for FacetAdded to duplicate my facets -----
  296.     FW_CFrameProxyFrameIterator iter(ev, embeddingSourceFrame);
  297.     for (FW_CProxyFrame* proxyFrame = iter.First(ev); iter.IsNotComplete(ev); proxyFrame = iter.Next(ev))
  298.     {    
  299.         FW_Boolean wasInMemory = proxyFrame->IsFrameInMemory(ev);
  300.         
  301.         // ----- get the embedded frame -----
  302.         ODFrame* odEmbeddedSourceFrame = proxyFrame->GetFrame(ev);        
  303.         
  304.         // ----- get the embedded part -----
  305.         FW_CAcquiredODPart aqODEmbeddedPart = odEmbeddedSourceFrame->AcquirePart(ev);
  306.     
  307.         // ----- Create the embedded Frame (proxyFrame) -----
  308.         FW_CAcquiredODShape aqFrameShapeCopy(FW_CopyAndRelease(ev, odEmbeddedSourceFrame->AcquireFrameShape(ev, NULL)));
  309.         
  310.         FW_CAcquiredODFrame embeddedODFrame = PrivCreateEmbeddedFrame(ev,
  311.                                                             kODFrameObject,    // Always create embedded frames persistent
  312. //                                                            IsPersistent(ev) ? kODFrameObject : kODNonPersistentFrameObject,
  313.                                                             aqODEmbeddedPart,
  314.                                                             aqFrameShapeCopy,
  315.                                                             NULL,                                    // bias Canvas
  316.                                                             odEmbeddedSourceFrame->GetViewType(ev),
  317.                                                             odEmbeddedSourceFrame->GetPresentation(ev),
  318.                                                             odEmbeddedSourceFrame->IsOverlaid(ev),
  319.                                                             odEmbeddedSourceFrame->IsSubframe(ev));
  320.         
  321.         // ----- Create the proxyFrame -----
  322.         FW_CProxyFrame* newProxyFrame = proxyFrame->GetProxy(ev)->PrivNewProxyFrame(ev, GetPart(ev), this, embeddedODFrame);
  323.  
  324.         // ----- Set the frame group
  325.         newProxyFrame->PrivSetFrameGroup(ev, odEmbeddedSourceFrame->GetFrameGroup(ev));
  326.         
  327.         // ----- Notify the Embedded frame-----
  328.         aqODEmbeddedPart->AttachSourceFrame(ev, newProxyFrame->GetFrame(ev), odEmbeddedSourceFrame);
  329.                 
  330.         // ----- If was not in memory Release back the embedded frame -----
  331.         if (!wasInMemory)
  332.             proxyFrame->Release(ev);
  333.     }
  334. }
  335.  
  336. //----------------------------------------------------------------------------------------
  337. //    FW_CEmbeddingFrame::PrivRemoveEmbeddedFrame
  338. //----------------------------------------------------------------------------------------
  339.  
  340. void FW_CEmbeddingFrame::PrivRemoveEmbeddedFrame(Environment* ev, FW_CProxyFrame* proxyFrame)
  341. {
  342.     //     If called means that the embedded frame is in memory
  343.     //    Be sure it is in memory
  344.     ODFrame* odEmbeddedFrame = proxyFrame->GetFrame(ev);
  345.  
  346.     // ----- Detach the proxyframe -----
  347.     proxyFrame->PrivDetach(ev);
  348.  
  349.     // ----- remove it from the proxy (will delete it) -----
  350.     proxyFrame->GetProxy(ev)->PrivDeleteProxyFrame(ev, proxyFrame);
  351. }
  352.  
  353. //----------------------------------------------------------------------------------------
  354. //    FW_CEmbeddingFrame::HighlightChanged
  355. //----------------------------------------------------------------------------------------
  356.  
  357. void FW_CEmbeddingFrame::HighlightChanged(Environment *ev, ODFacet* odFacet)
  358. {
  359.     // If I am in frame view type notify all my embedded facet...
  360.     if (GetViewType(ev) == FW_CPart::gViewAsFrameToken)
  361.     {
  362.         // ----- Notify all my embedded facets -----
  363.         ODHighlight highlight = odFacet->GetHighlight(ev);
  364.         
  365.         FW_CFacetIterator ite(ev, odFacet, kODChildrenOnly, kODFrontToBack);
  366.         for (ODFacet* embeddedFacet = ite.First(ev); ite.IsNotComplete(ev); embeddedFacet = ite.Next(ev))
  367.         {
  368.             embeddedFacet->ChangeHighlight(ev, highlight);
  369.         }
  370.     }
  371.     // ...otherwise just invalidate the facet
  372.     else
  373.     {
  374.         odFacet->Invalidate(ev, NULL, NULL);    // NULL for the shape is fine    
  375.     }
  376. }
  377.  
  378. //----------------------------------------------------------------------------------------
  379. //    FW_CEmbeddingFrame::FrameRemoved
  380. //----------------------------------------------------------------------------------------
  381. //    I should not have to worry about my embedded facets because before the frame is removed
  382. //    its facets should have been removed, removing the embedded facets
  383.  
  384. void FW_CEmbeddingFrame::FrameRemoved(Environment* ev, FW_Boolean toStorage)
  385. {
  386.     // ----- Collect the proxyFrames in a temporary collections -----
  387.     FW_TOrderedCollection<FW_CProxyFrame> tempCollect;
  388.     FW_CProxyFrame*  proxyFrame;
  389.     
  390.     FW_CFrameProxyFrameIterator ite1(ev, this);
  391.     for (proxyFrame = ite1.First(ev); ite1.IsNotComplete(ev); proxyFrame = ite1.Next(ev))
  392.     {
  393.         tempCollect.AddLast(proxyFrame);
  394.     }
  395.  
  396.     // ----- Now we can call close or remove
  397.     FW_TOrderedCollectionIterator<FW_CProxyFrame> ite2(&tempCollect);
  398.     for (proxyFrame = ite2.First(); ite2.IsNotComplete(); proxyFrame = ite2.Next())
  399.     {
  400.         if (toStorage)
  401.             proxyFrame->PrivClose(ev);
  402.         else
  403.             this->PrivRemoveEmbeddedFrame(ev, proxyFrame);
  404.     }
  405.     
  406.     // Don't have to call tempCollect.RemoveAll() because the __dt does it
  407.     
  408.     // ----- Call inherited -----
  409.     FW_CFrame::FrameRemoved(ev, toStorage);
  410. }
  411.  
  412. //----------------------------------------------------------------------------------------
  413. //    FW_CEmbeddingFrame::FacetAdded
  414. //----------------------------------------------------------------------------------------
  415. //    When overridden call inherited::FacetAdded FIRST
  416.  
  417. void FW_CEmbeddingFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  418. {    
  419.     // ----- Call inherited first
  420.     FW_CFrame::FacetAdded(ev, facet, facetCount);
  421.     
  422.     // ----- Add facets to each one of my embedded frame (that are in memory) -----
  423.     if (GetViewType(ev) == FW_CPart::gViewAsFrameToken)
  424.     {
  425.         FW_CFrameProxyFrameIterator ite(ev, this);
  426.         for (FW_CProxyFrame* proxyFrame = ite.First(ev); ite.IsNotComplete(ev); proxyFrame = ite.Next(ev))
  427.         {
  428.             proxyFrame->CreateFacets(ev, this, facet);
  429.         }
  430.     }
  431. }
  432.  
  433. //----------------------------------------------------------------------------------------
  434. //    FW_CEmbeddingFrame::FacetRemoved
  435. //----------------------------------------------------------------------------------------
  436. //    When overridden call inherited::FacetRemoved LAST
  437.  
  438. void FW_CEmbeddingFrame::FacetRemoved(Environment* ev, ODFacet* facet, unsigned short facetCount)
  439. {
  440.     // ----- Remove Embedded Facets
  441.     FW_CFrameProxyFrameIterator ite(ev, this);
  442.     for (FW_CProxyFrame* proxyFrame = ite.First(ev); ite.IsNotComplete(ev); proxyFrame = ite.Next(ev))
  443.         proxyFrame->RemoveFacets(ev, this, facet);
  444.     
  445.     // ----- Call inherited
  446.     FW_CFrame::FacetRemoved(ev, facet, facetCount);
  447. }
  448.  
  449. //----------------------------------------------------------------------------------------
  450. //    FW_CEmbeddingFrame::EmbeddedFacetAdded
  451. //----------------------------------------------------------------------------------------
  452.  
  453. void FW_CEmbeddingFrame::EmbeddedFacetAdded(Environment* ev, ODFacet* odFacet)
  454. {
  455. FW_UNUSED(ev);
  456. FW_UNUSED(odFacet);
  457. }
  458.  
  459. //----------------------------------------------------------------------------------------
  460. //    FW_CEmbeddingFrame::EmbeddedFacetRemoved
  461. //----------------------------------------------------------------------------------------
  462.  
  463. void FW_CEmbeddingFrame::EmbeddedFacetRemoved(Environment* ev, ODFacet* odFacet)
  464. {
  465. FW_UNUSED(ev);
  466. FW_UNUSED(odFacet);
  467. }
  468.  
  469. //----------------------------------------------------------------------------------------
  470. //    FW_CEmbeddingFrame::HasASelectedEmbeddedFacet
  471. //----------------------------------------------------------------------------------------
  472.  
  473. FW_Boolean FW_CEmbeddingFrame::HasASelectedEmbeddedFacet(Environment* ev) const
  474. {
  475.     FW_CFrameProxyFrameIterator iter(ev, this);
  476.     for (FW_CProxyFrame* proxyFrame = iter.First(ev); iter.IsNotComplete(ev); proxyFrame = iter.Next(ev))
  477.     {
  478.         if (proxyFrame->GetProxy(ev)->GetSelectState(ev))
  479.             return TRUE;
  480.     }
  481.     
  482.     return FALSE;
  483. }
  484.  
  485. //----------------------------------------------------------------------------------------
  486. //    FW_CEmbeddingFrame::HandleAdjustMenus
  487. //----------------------------------------------------------------------------------------
  488.  
  489. FW_Boolean FW_CEmbeddingFrame::HandleAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  490.                                             FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  491. {
  492.     if (hasMenuFocus)
  493.     {
  494.         FW_Boolean hasSelectedEmbeddedFacets = HasASelectedEmbeddedFacet(ev);
  495.         
  496.         menuBar->EnableCommand(ev, kODCommandGetPartInfo, hasSelectedEmbeddedFacets);
  497.         menuBar->EnableCommand(ev, kODCommandOpen, hasSelectedEmbeddedFacets);
  498.  
  499.         menuBar->EnableCommand(ev, kODCommandInsert, !GetPart(ev)->IsReadOnly(ev));
  500.  
  501. #ifdef FW_BUILD_WIN
  502.         GetPart(ev)->WinEnableEmbedMenu(ev, menuBar);
  503. #endif
  504.     }
  505.     
  506.     return FW_CFrame::HandleAdjustMenus(ev, menuBar, hasMenuFocus, isRoot);
  507. }
  508.  
  509. //----------------------------------------------------------------------------------------
  510. //    FW_CEmbeddingFrame::HandleMenu
  511. //----------------------------------------------------------------------------------------
  512.  
  513. FW_Boolean FW_CEmbeddingFrame::HandleMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  514. {
  515.     FW_Boolean result = TRUE;
  516.     ODCommandID commandID = theMenuEvent.GetCommandID(ev);
  517.     
  518. #ifdef FW_BUILD_WIN
  519.     ODPart *embeddedPart = GetPart(ev)->WinCreateEmbeddedPartFromCommand(ev, commandID);
  520.     if (embeddedPart != NULL)
  521.     {
  522.         this->EmbedSingleFrame(ev, embeddedPart, NULL, NULL, GetPresentation(ev)->GetDefaultEmbeddedFrameViewType(ev));
  523.         return TRUE;
  524.     }
  525. #endif
  526.  
  527.     FW_CSelection* selection = this->GetPresentation(ev)->GetSelection(ev);
  528.     switch (commandID)
  529.     {
  530.         case kODCommandInsert:
  531.             {
  532.                 FW_ASSERT(!GetPart(ev)->IsReadOnly(ev));
  533.  
  534. #ifdef FW_BUILD_WIN
  535.                 FW_COpenFileParameters openFileParameters;    // Uses default open file parameters
  536.                 DoInsert(ev, openFileParameters);
  537. #endif            
  538. #ifdef FW_BUILD_MAC
  539.                 FW_COpenFileParameters openFileParameters(&FW_MacInsertFilterProc);            // Allows only odtm documents
  540.                 DoInsert(ev, openFileParameters);
  541. #endif            
  542.             }
  543.             break;
  544.             
  545.         case kODCommandGetPartInfo:
  546.             ShowPartInfo(ev);
  547.             break;
  548.             
  549.         case kODCommandOpen:
  550.             OpenSelection(ev);
  551.             break;
  552.  
  553.         default:
  554.             result = FW_CFrame::HandleMenu(ev, theMenuEvent);
  555.     };
  556.     
  557.     return result;
  558. }
  559.  
  560. //----------------------------------------------------------------------------------------
  561. //    FW_CEmbeddingFrame::NewInsertCommand
  562. //----------------------------------------------------------------------------------------
  563.  
  564. FW_CInsertCommand* FW_CEmbeddingFrame::NewInsertCommand(Environment* ev, const FW_PFileSpecification& fileSpec)
  565. {
  566. FW_UNUSED(ev);
  567. FW_UNUSED(fileSpec);
  568.  
  569.     FW_DEBUG_MESSAGE("NewInsertCommand: subclass responsability");
  570.     return NULL;
  571. }
  572.  
  573. //----------------------------------------------------------------------------------------
  574. //    FW_CEmbeddingFrame::DoInsert
  575. //----------------------------------------------------------------------------------------
  576.  
  577. void FW_CEmbeddingFrame::DoInsert(Environment* ev, FW_COpenFileParameters& openFileParameters)
  578. {
  579.     FW_PFileSpecification fileSpec(ev, FW_CChooseFile::ChooseFileToOpen(openFileParameters));
  580.     
  581.     if (fileSpec != NULL)
  582.     {
  583.         FW_CInsertCommand* cmd = this->NewInsertCommand(ev, fileSpec);
  584.         if (cmd)
  585.             cmd->Execute(ev);
  586.     }
  587. }
  588.  
  589. //----------------------------------------------------------------------------------------
  590. //    FW_CEmbeddingFrame::OpenSelection
  591. //----------------------------------------------------------------------------------------
  592.  
  593. void FW_CEmbeddingFrame::OpenSelection(Environment* ev)
  594. {
  595.     //     I need to collect first the proxyframe that I want to open because opening the first 
  596.     //    window will unselect the other one
  597.     
  598.     FW_CProxyFrame* proxyFrame;
  599.     
  600.     FW_TOrderedCollection<FW_CProxyFrame> temp;
  601.  
  602.     FW_CFrameProxyFrameIterator iter(ev, this);
  603.     for (proxyFrame = iter.First(ev); iter.IsNotComplete(ev); proxyFrame = iter.Next(ev))
  604.     {
  605.         if (proxyFrame->GetProxy(ev)->GetSelectState(ev))
  606.             temp.AddLast(proxyFrame);
  607.     }
  608.     
  609.     FW_TOrderedCollectionIterator<FW_CProxyFrame> iter2(&temp);
  610.     for (proxyFrame = iter2.First(); iter2.IsNotComplete(); proxyFrame =  iter2.Next())
  611.     {
  612.         proxyFrame->GetProxy(ev)->OpenInWindow(ev, proxyFrame);
  613.     }
  614.     
  615.     // the destructor of temp will call RemoveAll
  616. }
  617.  
  618. //----------------------------------------------------------------------------------------
  619. //    FW_CEmbeddingFrame::ShowPartInfo
  620. //----------------------------------------------------------------------------------------
  621.  
  622. void FW_CEmbeddingFrame::ShowPartInfo(Environment* ev)
  623. {
  624.     FW_CFrameProxyFrameIterator iter(ev, this);
  625.     for (FW_CProxyFrame* proxyFrame = iter.First(ev); iter.IsNotComplete(ev); proxyFrame = iter.Next(ev))
  626.     {
  627.         FW_MProxy *proxy = proxyFrame->GetProxy(ev);
  628.         FW_ASSERT(proxy);
  629.         
  630.         if (proxy->GetSelectState(ev))
  631.         {
  632.             // ----- Try first the active facet -----
  633.             ODFacet* facet = this->GetActiveFacet(ev);
  634.             
  635.             // ----- If not Active facet try the first facet -----
  636.             if (facet == NULL)
  637.             {
  638.                 FW_CFrameFacetIterator iteFrame(ev, this);
  639.                 facet = iteFrame.First(ev);
  640.             }
  641.             FW_ASSERT(facet != NULL);
  642.             
  643.             // [HLX] We are passing the first facet but we need to be a little bit more smart 
  644.             // about that. We should pass the selected one or if there is no selection do it on ourself
  645.             FW_CEmbeddedODFacetsIterator ite(ev, proxy, facet, kODFrontToBack);
  646.             ODFacet* firstEmbeddedFacet = ite.First(ev);
  647.             FW_ASSERT(firstEmbeddedFacet != NULL);
  648.             
  649.             ODFrame* embeddedFrame = proxyFrame->GetFrame(ev);
  650.             ODTypeToken oldViewType = embeddedFrame->GetViewType(ev);
  651.  
  652.             ODInfo* info = GetPart(ev)->GetSession(ev)->GetInfo(ev);
  653.             info->ShowPartFrameInfo(ev, firstEmbeddedFacet, !GetPart(ev)->IsReadOnly(ev));
  654.  
  655.             ODTypeToken newViewType = embeddedFrame->GetViewType(ev);
  656.             
  657.             // ----- Propagate the view type to other sibling frames -----
  658.             if (oldViewType != newViewType)
  659.             {
  660.                 FW_CProxyEmbeddedFrameIterator iter2(ev, proxy);
  661.                 for (ODFrame* sibling = iter2.First(ev); iter2.IsNotComplete(ev); sibling = iter2.Next(ev))
  662.                 {
  663.                     sibling->ChangeViewType(ev, newViewType);
  664.                 }
  665.             }
  666.         }
  667.     }
  668. }
  669.  
  670. //----------------------------------------------------------------------------------------
  671. //    FW_CEmbeddingFrame::RevealFrame    
  672. //----------------------------------------------------------------------------------------
  673.  
  674. FW_Boolean FW_CEmbeddingFrame::RevealFrame(Environment *ev, 
  675.                                         ODFrame* embeddedFrame, 
  676.                                         ODShape* revealShape)
  677. {
  678. FW_UNUSED(ev);
  679. FW_UNUSED(embeddedFrame);
  680. FW_UNUSED(revealShape);
  681.  
  682.     return FALSE;
  683. }
  684.  
  685. //----------------------------------------------------------------------------------------
  686. //    FW_CEmbeddingFrame::ViewTypeChanged
  687. //----------------------------------------------------------------------------------------
  688.  
  689. void FW_CEmbeddingFrame::ViewTypeChanged(Environment* ev, ODTypeToken newViewType, ODTypeToken oldViewType)
  690. {
  691.     FW_CFrame::ViewTypeChanged(ev, newViewType, oldViewType);
  692.     
  693.     FW_CFrameProxyFrameIterator ite(ev, this);
  694.     for (FW_CProxyFrame* proxyframe = ite.First(ev); ite.IsNotComplete(ev); proxyframe = ite.Next(ev))
  695.     {
  696.         if (oldViewType == FW_CPart::gViewAsFrameToken)
  697.             proxyframe->RemoveAllFacets(ev);
  698.         else
  699.             proxyframe->CreateAllFacets(ev);
  700.     }
  701. }
  702.  
  703. //----------------------------------------------------------------------------------------
  704. //    FW_CEmbeddingFrame::AdjustCursor
  705. //----------------------------------------------------------------------------------------
  706.  
  707. FW_Boolean FW_CEmbeddingFrame::AdjustCursor(Environment *ev, ODFacet* odFacet, const FW_CPoint& theMousePoint)
  708. {
  709.     // ----- Test if mouse on the active border of an embedded facet -----
  710.     FW_Boolean cursorInActiveBorder = FALSE;
  711.     
  712.     ODArbitrator* arbitrator =  GetPart(ev)->GetSession(ev)->GetArbitrator(ev);
  713.     FW_CAcquiredODFrame aqActiveFrame = arbitrator->AcquireFocusOwner(ev, FW_CPart::gSelectionFocusToken);
  714.     if (aqActiveFrame != NULL)
  715.     {
  716.         FW_CODFrameFacetIterator iter(ev, aqActiveFrame);
  717.         
  718.         FW_CPoint windowMouse(theMousePoint);
  719.         FW_FrameToWindow(ev, odFacet, windowMouse);
  720.         
  721.         for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
  722.         {
  723.             FW_CPoint temp(windowMouse);
  724.             FW_WindowToFrame(ev, facet, temp);
  725.             ODPoint odFramePoint = temp;
  726.             
  727.             if (facet->ActiveBorderContainsPoint(ev, &odFramePoint, NULL))
  728.             {
  729.                 cursorInActiveBorder = TRUE;
  730.                 break;
  731.             } 
  732.         }
  733.     }
  734.     
  735.     if (cursorInActiveBorder)
  736.         FW_gOpenHandCursor.Select();
  737.     
  738.     return cursorInActiveBorder;
  739. }
  740.  
  741. //----------------------------------------------------------------------------------------
  742. //    FW_CEmbeddingFrame::GetEmbeddedFacet
  743. //----------------------------------------------------------------------------------------
  744. //    Return the <first> facet belonging to proxy embedded in 'facet' 
  745.  
  746. ODFacet* FW_CEmbeddingFrame::GetEmbeddedFacet(Environment* ev, ODFacet* facet, FW_MProxy* proxy)
  747. {
  748.     ODID sequenceNumber = proxy->GetSequenceNumber(ev);
  749.     ODID frameGroup = proxy->GetFrameGroup(ev);
  750.     
  751.     FW_CFacetIterator i(ev, facet, kODChildrenOnly, kODFrontToBack);
  752.  
  753.     FW_CAcquiredODPart aqEmbeddedPart = proxy->AcquireEmbeddedPart(ev);
  754.     for (ODFacet* embeddedFacet = i.First(ev); i.IsNotComplete(ev); embeddedFacet = i.Next(ev))
  755.     {
  756.         ODFrame* embeddedFrame = embeddedFacet->GetFrame(ev);
  757.         FW_CAcquiredODPart aqODPart = embeddedFrame->AcquirePart(ev);
  758.         if (aqODPart == aqEmbeddedPart && 
  759.             embeddedFrame->GetSequenceNumber(ev) == sequenceNumber &&
  760.             embeddedFrame->GetFrameGroup(ev) == frameGroup)
  761.             return embeddedFacet;
  762.     }
  763.         
  764.     return NULL;
  765. }
  766.  
  767. //----------------------------------------------------------------------------------------
  768. //    FW_CEmbeddingFrame::ODtoFWEmbeddingFrame
  769. //----------------------------------------------------------------------------------------
  770.  
  771. FW_CEmbeddingFrame* FW_CEmbeddingFrame::ODtoFWEmbeddingFrame(Environment* ev, ODFrame* odFrame)
  772. {
  773.     FW_CEmbeddingFrame* frame = NULL;
  774.     
  775.     if (odFrame)
  776.     {
  777.         FW_CFrame* fwframe = (FW_CFrame*)odFrame->GetPartInfo(ev);
  778.         frame = fwframe ? FW_DYNAMIC_CAST(FW_CEmbeddingFrame, fwframe) : NULL;
  779.     }
  780.     
  781.     return frame;
  782. }
  783.  
  784. //---------------------------------------------------------------------------------------
  785. //    FW_CEmbeddingFrame::PrivDragging
  786. //---------------------------------------------------------------------------------------
  787.  
  788. void FW_CEmbeddingFrame::PrivDragging(Environment *ev, FW_Boolean state)
  789. {
  790.     FW_CFrameProxyFrameIterator ite(ev, this);
  791.     for (FW_CProxyFrame* proxyFrame = ite.First(ev); ite.IsNotComplete(ev); proxyFrame = ite.Next(ev))
  792.     {
  793.         // FW_MProxy is doing the right check before setting the embedded ODFrame
  794.         proxyFrame->GetProxy(ev)->PrivSetDragging(ev, state); 
  795.     }    
  796. }
  797.